package madsgtdinterface;


import java.awt.Toolkit;
import java.util.ListIterator;
import java.util.Timer;
import java.util.TimerTask;
import thunderbirdgtd.GTDParent;
import thunderbirdgtd.entities.Action;
import thunderbirdgtd.entities.Alarm;
import thunderbirdgtd.entities.BaseActionOrProject;



public class AlarmClock {
    Toolkit toolkit;
    Timer timer;
 GTDParent pp;
 MainFrame mainframe;
    public AlarmClock(GTDParent p, MainFrame mf){
        mainframe = mf;
         pp=p;
        toolkit = Toolkit.getDefaultToolkit();
        timer = new Timer();
       
        timer.schedule(new RemindTask(pp),
                       0,        //initial delay
                       1*5000);  //subsequent rate
    }

    class RemindTask extends TimerTask {
        GTDParent pp;
        RemindTask(GTDParent p){
            pp=p;
        }
        public void run() {
                ListIterator<Action> li = pp.actions.listIterator();
                ListIterator<Alarm> lista;
                Alarm a;
                Action aa;
                while(li.hasNext()){
                    aa = li.next();
                    lista = aa.checkAlarms().listIterator();
                    while(lista.hasNext()){
                        a = lista.next();
                        madsgtdinterface.Alarm Al;
                        Al=new madsgtdinterface.Alarm(mainframe, true);
                        Al.setVisible(true);
                        aa.alarms.remove(a);
                        return ;
                    }
                }
        }
        
        
    }

}